<template>
  <div class="rightBodyContent">
    <div class="rightBodyContent-in">
      <div class="search-list mb-10">
        <el-input v-model="editForm.name" auto-complete="off" placeholder="填写卷目名" size="small"
                  class="w-140 mr-10"></el-input>
        <el-input v-model="editForm.sn" auto-complete="off" placeholder="填写卷目号" size="small" class="w-140"></el-input>
        <el-button size="small" type="primary" plain class=" ml-10" @click="search('search')">搜索</el-button>
        <el-button size="small" plain @click="search('resct')">重置</el-button>
        <el-button size="small" type="primary" plain @click="addStudent(0)"><i class="el-icon-plus"></i>申请档案
        </el-button>
      </div>
      <!--本体列表，数据 -->
      <div class="table-body">
        <div class="table-body-box">
          <el-table
              ref="multipleTable"
              :data="arryList"
              :stripe="tableStyle.tableStripe"
              :border="tableStyle.tableBorder"
              tooltip-effect="dark"
              header-cell-class-name="table-text-c"
              style="width: 100%">
            <el-table-column
                prop="name"
                label="卷目名"
                align="center">
            </el-table-column>
            <el-table-column
                label="卷目号"
                align="center"
                prop="sn">
            </el-table-column>
            <el-table-column
                prop="content"
                label="用途"
                align="center">
            </el-table-column>
            <el-table-column
                prop="status"
                label="状态"
                align="center">
              <!--          0待审核1通过2驳回3完成 -->
              <template slot-scope="scope">
                <!--                0待审核1待借出2待归还3已归还4驳回-->
                <span v-if="scope.row.status==0">待审核</span>
                <span v-if="scope.row.status==1">待借出</span>
                <span v-if="scope.row.status==2">待归还</span>
                <span v-if="scope.row.status==3">已归还</span>
                <span v-if="scope.row.status==4" class="examinBtn">已驳回 <i @click="shoeExaminFn(scope.$index)">查看驳回说明</i></span>
              </template>
            </el-table-column>
            <el-table-column
                label="操作"
                align="center"
                width="90">
              <template slot-scope="scope">
                <el-button v-if="scope.row.status==0" type="danger" plain size="small"
                           @click="deleteList(scope.row)">删除
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <!--工具条 分页-->
      <el-col :span="24" class="toolbar">
        <el-pagination
            background
            layout="total, prev, pager, next"
            :total="page.total"
            :page-size="page.pagesize"
            @current-change="handleSizeChange">
        </el-pagination>
      </el-col>
    </div>
    <applyLicence :visible.sync="detailVisible" @InitFn="InitFn" :sealId="sealId"></applyLicence>
  </div>
</template>

<script>
import {pagination, tableoption} from '@/utils/util.js'
import applyLicence from "./addEdit";
import {files_index, files_delete} from '@/api/admin/badge'

export default {
  components: {
    applyLicence,
  },
  data() {
    return {
      arryList: [], // 页面数据列表
      // 设置table样式
      tableStyle: tableoption,
      // 设置table页面分页所需
      page: {
        pageindex: pagination.pageIndex,
        pagesize: pagination.pageSize,
        total: pagination.total
      },
      editForm: {
        name: '',
        sn: '',
        style: 1
      },
      sealId: 0,
      detailVisible: false
    }
  },
  created() {
    this.InitFn();
  },
  methods: {
    // 初始化
    InitFn() {
      // 0待审核1通过2驳回3借出4归还
      let option_ = JSON.parse(JSON.stringify(this.editForm))
      option_.p = this.page.pageindex
      files_index(option_).then(res => {
        this.arryList = JSON.parse(JSON.stringify(res.list.data))
        this.page.total = res.list.total
      })
    },
    // 分页
    handleSizeChange(val) {
      this.page.pageindex = val
      this.InitFn()
    },
    search(option) {
      this.page.pageindex = 1;
      if (option === 'resct') {
        this.editForm.name = ''
        this.editForm.sn = ''
      }
      this.InitFn()
    },
    shoeExaminFn(index) {
      this.$confirm(this.arryList[index].content, '驳回说明', {
        showCancelButton: false,
        confirmButtonText: '确认',
        type: 'warning'
      }).then(() => {
        // :visible.sync="detailVisible" @InitFn="InitFn" :sealId="sealId"
        // this.sealId = this.arryList[index].id;
        // this.detailVisible = true;
      }).catch(() => {
      })
    },
    addStudent(row) {
      this.sealId = row || 0;
      this.detailVisible = true;
    },
    deleteList(row) {
      let this_ = this
      this.$confirm('此操作将删除【' + row.name + '】档案, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        closeOnClickModal: false,
        type: 'warning'
      }).then(() => {
        this_.deletFn(row.id)
      }).catch(() => {
      })
    },
    deletFn(id) {
      files_delete({id: id}).then(res => {
        console.log('res:', res)
        if (!res.code) {
          this.$message.success(res.msg)
          this.InitFn()
        }
      })
    },
  },
  mounted() {
  },
}
</script>

<style scoped>

.wx-user-box-line img {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  margin-right: 5px;
}

.wx-user-box-line {
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-wx {
  cursor: pointer;
  padding: 5px;
}

.btn-wx:hover {
  color: #1b8de5;
  text-decoration: underline;
}

.delet-wx {
  color: red;
  cursor: pointer;
}

.delet-wx:hover {
  text-decoration: underline;
}

.tab-body {
  display: flex;
  align-items: center;
}

.tab-box {
  flex: 1;
}

.examinBtn {
  display: flex;
  flex-direction: column;
  align-items: center;
  color: red;
}

.examinBtn i {
  font-style: normal;
  color: #1b8de5;
  cursor: pointer;
  font-size: 12px;
}
</style>
